package com.star.eastern.blee.customview;

import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.drawable.Drawable;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.star.eastern.blee.R;

public class HdmiViewItem extends LinearLayout{
//For GUI
    private LinearLayout rlViewPan;
    private LinearLayout ivHdmiIcon;
    private TextView tvHdmiName;

//For State
    private Boolean isEnabled;

//For Property
    private int textColor;
    private int textDisableColor;
    private int backgroundColor;
    private int backgroundDisableColor;
    private Drawable buttonDrawable;
    private Drawable buttonDisableDrawable;

    public HdmiViewItem(Context context) {
        super(context, null);
    }

    public HdmiViewItem(Context context, AttributeSet attrs) {
        super(context, attrs);
        isEnabled = false;
        TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.HdmiCustomView);
        String text = typedArray.getString(R.styleable.HdmiCustomView_text);
        textColor = typedArray.getColor(R.styleable.HdmiCustomView_textColor,
                getResources().getColor(R.color.white));
        textDisableColor = typedArray.getColor(R.styleable.HdmiCustomView_textDisableColor,
                getResources().getColor(R.color.colorMain));
        backgroundColor = typedArray.getColor(R.styleable.HdmiCustomView_backgroundColor,
                getResources().getColor(R.color.colorMain));
        backgroundDisableColor = typedArray.getColor(R.styleable.HdmiCustomView_backgroundDisableColor,
                getResources().getColor(R.color.normalButtonDisabled));
        buttonDrawable = typedArray.getDrawable(R.styleable.HdmiCustomView_hdmiButtonBackground);
        buttonDisableDrawable = typedArray.getDrawable(R.styleable.HdmiCustomView_hdmiButtonDisableBackground);

        typedArray.recycle();
        LayoutInflater inflater = (LayoutInflater) context
                .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        inflater.inflate(R.layout.hdmicustomview, this, true);
        rlViewPan = this.findViewById(R.id.rl_viewpan);
        ivHdmiIcon = this.findViewById(R.id.iv_hdmiicon);
        tvHdmiName = this.findViewById(R.id.tv_hdmi_name);
        tvHdmiName.setText(text);
        setProperty();
    }

    public void setProperty()
    {
        if(this.isEnabled)
        {
            setViewPanBackgroundColor(this.backgroundColor);
            setHdmiNameTextColor(this.textColor);
            setIvHdmiIcon(this.buttonDrawable);
        }
        else{
            setViewPanBackgroundColor(this.backgroundDisableColor);
            setHdmiNameTextColor(this.textDisableColor);
            setIvHdmiIcon(this.buttonDisableDrawable);
        }
    }

    public void setViewPanBackgroundColor(int color)
    {
        this.rlViewPan.setBackgroundColor(color);
    }

    public void setIvHdmiIcon(Drawable drawable)
    {
        this.ivHdmiIcon.setBackground(drawable);
    }

    public void setHdmiNameTextColor(int color)
    {
        this.tvHdmiName.setTextColor(color);
    }

    public void setHdmiNameText(String s){this.tvHdmiName.setText(s);}
    public String HdmiNameText(){return tvHdmiName.getText().toString();}

    public void setIsEnabled(boolean flag)
    {
        this.isEnabled = flag;
        setProperty();
    }
}
